<?php
/**
 * Created by PhpStorm.
 * User: yu
 * Date: 2017/1/5
 * Time: 下午4:44
 */

namespace Admin\Model;


use Common\Model\BaseModel;

class AdminModel extends BaseModel
{
	protected $pk = 'id';
	protected $tableName = 'admin';
	protected $_validate = [
		['uname','require','用户名不能为空'],
		['password','require','密码不能为空'],
	];

	public function checkLogin(){
		$post = I('post.');
		if(!$this->create()){
			return false;
		}
		$user = $this->where("uname='{$post['uname']}'")->find();
		if(!$user){
			$this->error = '用户不存在';
			return false;
		}
//		echo I('post.password','','md5');die;
		if(md5($post['password'])!=$user['password']){
			$this->error = '密码错误';return false;
		}

		$_SESSION['admin']['id'] = $user['id'];
		$_SESSION['admin']['uname'] = $user['uname'];
		return true;
	}



}